package com.api.tag.deletetag;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.ITagApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.ObjectResultApi;
import com.zyncro.api.model.TagApi;
import com.zyncro.api.model.TagApiType;

@ContextConfiguration(locations = { "classpath:/tags/tags-context.xml" })
public class DeleteTagExternalAdmin extends AbstractApiTest {

	@Value("#{tagtest['user.externalAdministrator'].appId}")
	private String externalUrn;

	@Value("#{tagtest['user.externalAdministrator'].password}")
	private String externalPassword;

	private String tagUrn;

	@Value("#{tagtest['user.administrator'].appId}")
	private String adminUrn;

	@Value("#{tagtest['user.administrator'].password}")
	private String adminPassword;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(adminUrn, adminPassword);

		ObjectResultApi<TagApi> result = getApi().getService(ITagApiService.class).createTag("new", TagApiType.LOCATION);

		this.tagUrn = result.getObject().getUrn();

		getApi().login(externalUrn, externalPassword);
	}

	@Test(expectedExceptions = { ZyncroApiException.class })
	public void testDeleteTag() throws ZyncroApiException {

		getApi().getService(ITagApiService.class).deleteTag(tagUrn);
	}
}
